from django.shortcuts import render
from django.http import HttpResponse
import re

class AdminLoginMiddleware:
	def __init__(self,get_response):
		self.get_response = get_response

	def __call__(self,request):
		path = request.path

		lists = ['/myadmin/login/','/myadmin/verifycode/']
		if re.match('/myadmin/',path) and path not in lists:
		# 判断有没有登录 如果没有登返回到登录页面
			if request.session.get('adminuser','') == '':
				return HttpResponse('<script>alert("请先登录");location.href="/myadmin/login";</script>')





		response = self.get_response(request)
		return response